package com.hy.common.excel;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hy.common.utils.CommonUtils;
import com.hy.common.utils.MyObjectUtils;
import com.hy.common.utils.StateUtil;
import com.hy.entity.dto.HyPropertySearchDTO;
import com.hy.entity.dto.PlaceSearchDTO;
import com.hy.entity.pojo.HyPlace;
import com.hy.entity.vo.HyPlaceVO;
import com.hy.entity.vo.HyPropertyVO;
import com.hy.entity.vo.HyUserVO;
import com.hy.mapper.HyPlaceMapper;
import com.hy.service.HyPlaceService;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

@Component
public class HyPropertyPlaceExport extends AbstractExcelExport<HyPlaceVO>{

    private Integer count;

    @Resource
    private HyPlaceMapper placeMapper;
    @Resource
    private HyPlaceService placeService;

    public void exportWithBigData(HttpServletResponse response, String fileName,PlaceSearchDTO searchDTO){

        this.count=placeMapper.selectCount(new LambdaQueryWrapper<HyPlace>().and(wapper->
                wapper.eq(!ObjectUtils.isEmpty(searchDTO.getUnitId()),HyPlace::getUnitId,searchDTO.getUnitId())
                        .eq(MyObjectUtils.isNotBlank(searchDTO.getPlaceName()),HyPlace::getPlaceName,searchDTO.getPlaceName())
                        .eq(HyPlace::getDel,searchDTO.getDel())
                )).intValue();
        this.exportWithBigData(response, fileName,null,BeanUtil.beanToMap(searchDTO), HyPlaceVO.class);
    }


    //计算出导出的数量
    @Override
    protected Integer dataTotalCount(Map<String, Object> queryCondition) {
        return this.count;
    }

    /**
     * 每一个sheet存放的数据总数
     * @return
     */
    @Override
    protected Integer eachSheetTotalCount() {//每一个sheet存放的数据总数
        return 500000;
    }

    @Override
    protected Integer eachTimesWriteSheetTotalCount() {//每次写入sheet的总数
        return 5000;
    }

    @Override
    protected void buildDataList(List<HyPlaceVO> resultList, Map<String, Object> queryCondition, Integer pageNo, Integer pageSize) {

        for (HyPlaceVO hyPlaceVO : placeService.listPage(queryCondition, pageNo, pageSize)) {
            resultList.add(hyPlaceVO);
        }


//        if(CollUtil.isNotEmpty(entityDoList)){
//            entityDoList.forEach(item -> {
//                resultList.add(Arrays.asList(item.getPlaceId().toString(),item.getPlaceName(),item.getDepartmentName(),item.getUnitName(),
//                        item.getMgrName(),item.getArea()+"㎡",item.getCreateDate()
//                ));
////                resultList.add(Arrays.asList(String.valueOf(item.getId()),String.valueOf(item.getEmpno()),String.valueOf(item.getEname()),item.getJob(),String.valueOf(item.getMgr()),String.valueOf(item.getDeptno())));
//            });
//        }

    }
}
